﻿using Core;
using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace g_gongjianta
{
    [CreateAssetMenu(menuName = "Mini/g_gongjianta/Conf/TblSkill")]
    public partial class TblSkill : ScriptableObject, ITable
    {
        [Serializable]
        public class Dir
        {
            /// <summary>
            /// 0: 角色正向朝向
            /// 1: 摇杆正向朝向
            /// 2: 角色坐标指向攻击者坐标的方向
            /// </summary>
            public int Type;

            /// <summary>
            /// 偏转角度
            /// </summary>
            public float Angle;
        }

        [Serializable]
        public class Pos
        {
            public int Type;

            public Vector2 Offset;
        }

        [Serializable]
        public class Detech
        {
            /// <summary>
            /// 0：每帧检测
            /// n：间隔n帧检测
            /// </summary>
            [HorizontalGroup("row0")]
            public int Interval;

            //默认 矩形
            //public int Shape;
            [HorizontalGroup("row0")]
            public Vector2 Size = Vector2.one;

            /// <summary>
            /// 检测目标类型
            /// </summary>
            [HorizontalGroup("row0")]
            public int Target;

            /// <summary>
            /// 命中目标个数上限
            /// </summary>
            [HorizontalGroup("row0")]
            public int Limit;
        }

        [Serializable]
        public class Offset
        {
            /// <summary>
            /// 0: 线段
            /// 1: Sin
            /// </summary>
            public int Type;

            public Vector2[] Points;
        }

        [Serializable]
        public class Link
        {
            [HorizontalGroup("row0")]
            public ESkillLinkType Type;

            [HorizontalGroup("row0")]
            public int SkillId;

            //[Tooltip("帧数序号从0开始，最后一帧为Duration-1")]
            [HorizontalGroup("row0")]
            public int StartFrame;

            //[HideInInspector]
            [HorizontalGroup("row0")]
            public int EndFrame;
        }

        [Serializable]
        public class Conf
        {
            [HorizontalGroup("row0")]
            public int Id;

            [HorizontalGroup("row0")]
            public string Name;

            [HorizontalGroup("row0")]
            public string AnimName;

            //[Tooltip("技能时长（帧数）")]
            [HorizontalGroup("row0")]
            public int Duration;

            [HorizontalGroup("row0")]
            public int LinkDefault;

            public Link[] Links;

            // public MoveEvt[] MoveEvts;
            public BulletEvt[] BulletEvts;
            // public SoundEvt[] SoundEvts;
            // public EffectEvt[] EffectEvts;
            // public ActionEvt[] ActionEvts;
        }

        public int IdleId;
        public int DeadId;

        [SerializeField]
        private Conf[] Confs;

        private readonly Dictionary<int, Conf> dict = new();

        public Conf Find(int id)
        {
            if (dict.ContainsKey(id))
            {
                return dict[id];
            }

            for (int i = 0; i < Confs.Length; i++)
            {
                if (Confs[i].Id == id)
                {
                    dict[id] = Confs[i];
                    return Confs[i];
                }
            }

            return null;
        }
    }
}